package khai.spring.util;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;

/**
 * @author Khai Loon
 * @version 2017/4/13 0013 下午 4:10
 */
public class XmlConfig {

    public static void main(String[] args) {
    }

    public String getConfig(String springXml) {

        InputStream stream = getClass().getClassLoader().getResourceAsStream(springXml);
        Document doc;
        try {
            doc = new SAXReader().read(stream);
        } catch (DocumentException e) {
            throw new RuntimeException("请检查xml配置");
        }
        Element elem = null;
        if (doc != null) {
            elem = doc.getRootElement().element("component-scan");
        }
        return elem.attributeValue("base-package");
    }
}
